/**
 * 
 */
package com.sesame.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.sesame.domain.User;
import com.sesame.service.UserService;

/**
 * @author shubeta
 * 
 */
public class FindPwdController extends SimpleFormController {

    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {

        User user = (User) command;
        
        Map model = errors.getModel();
        model.put("user", user);
        
        boolean isSend = userService.findPassword(user, model);
        
        if (isSend) {
            return new ModelAndView(getSuccessView(), model);
        } 
        else {
            return new ModelAndView(getFormView(), model);
        }

    }

}
